package com.guge.sports.controller;


import com.guge.sports.entity.Dto.Option;
import com.guge.sports.entity.Dto.SelectionCourseHappeningDto;
import com.guge.sports.entity.Dto.StCourseDto;
import com.guge.sports.entity.StCourse;
import com.guge.sports.service.StCourseService;
import com.guge.sports.toolPackage.base.BaseController;
import com.guge.sports.toolPackage.utils.MyPager;
import com.guge.sports.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author testjava
 * @since 2022-09-14
 */
@Api(description = "课程管理接口")
@RestController
@RequestMapping("/sports/st-course")
public class StCourseController extends BaseController<StCourse> {

    @Autowired
    private StCourseService courseService;

    @ApiOperation(value = "课程管理分页查询")
    @PostMapping("/selectCoursePage")
    public R selectCoursePage(MyPager<StCourseDto> myPager, @RequestBody(required = false) StCourseDto courseDto){
        //System.out.println(courseDto);
        MyPager pager = courseService.selectCoursePage(myPager,courseDto);
        return R.ok().data("page", pager);
    }
    @ApiOperation(value = "课程添加")
    @PostMapping("/addCourse")
    public R addCourse(@RequestBody StCourse course){
        courseService.addCourse(course);
        return R.ok();
    }

    @ApiModelProperty(value = "选课分页查询")
    @PostMapping("/selectionCoursePage")
    public R selectionCourse(MyPager<StCourseDto> myPager,@RequestBody(required = false) StCourseDto stCourseDto){
        MyPager  pager = courseService.selectionCourse(myPager,stCourseDto);
        return R.ok().data("page",pager);
    }

    @ApiOperation(value = "选课情况")
    @PostMapping("/selectionCourseHappening")
    public R selectionCourseHappening(){
        List<SelectionCourseHappeningDto> list = courseService.selectionCourseHappening();
        return R.ok().data("page",list);
    }
    @ApiOperation(value = "下拉框")
    @GetMapping("/option")
    public R option(){
        List<Option> teacherName = courseService.getTeacherName();
        return R.ok().data("teacherName",teacherName);
    }

    @ApiOperation(value = "根据id下架课程")
    @GetMapping("/courseTakeDown/{id}")
    public R courseTakeDown(@PathVariable Long id){
        courseService.courseTakeDown(id);
        return R.ok().message("下架成功");
    }
    @ApiOperation(value = "根据id删除课程")
    @DeleteMapping("/deleteCourse/{id}")
    public R deleteCourse(@PathVariable Long id){
        courseService.deleteCourse(id);
        return R.ok().message("删除成功");
    }

    @ApiOperation(value = "编辑回显数据")
    @GetMapping("/getCourseId/{id}")
    public R getCourseById(@PathVariable Long id){
        StCourseDto  stCourseDto = courseService.getCourseById(id);
        return R.ok().data("course",stCourseDto);
    }

    @PostMapping("/updateById")
    @ApiOperation(value = "修改课程")
    public R updateCourse(@RequestBody StCourse courseDto){
//        courseService.updateCourse(courseDto);
        super.updateById(courseDto);
        return R.ok().message("修改成功");
    }

}

